﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Component;

public partial class BackEnd_CategoryModifyShow : System.Web.UI.UserControl
{
    public string _idCat = "";
    CategoryInfo info;
    string _UrlCateSub = BackEndQuery._AdminQuery + BackEndQuery._CategorySub + "&" + ConstString._Parent + ConstString._dauBang;
    string _UrlCateL = BackEndQuery._AdminQuery + BackEndQuery._CategoryL;
    protected void Page_Load(object sender, EventArgs e)
    {
        _idCat = Request.QueryString[ConstString._idcat] ?? "";
        
        if (_idCat != "")
            Load_Data();

    }
    private void Load_Data()
    {
        info = CategoryDB.GetById(ConvertType.ToInt(_idCat));
        txtSummary.Text = info.Summary;
        txtTen.Text = info.Name;
        txtParent.Text = info.Parent.ToString();
    }

    protected void cmdLuu_Click(object sender, EventArgs e)
    {
        info = CategoryDB.GetById(ConvertType.ToInt(_idCat));
        info.Summary = ConvertType.ToString(txtSummary.Text);
        info.Name = ConvertType.ToString(txtTen.Text);
        info.Parent = ConvertType.ToInt(txtParent.Text);
        if (CategoryDB.Update(info))
        {
            lbMessage.Text = ConstString._capNhatTC;
            if (info.Parent == 0)
                Response.Redirect(_UrlCateL);
            else
                Response.Redirect(_UrlCateSub + info.Parent.ToString());
        }
        else
            lbMessage.Text = ConstString._capNhatTB;
    }
    protected void cmdHuy_Click(object sender, EventArgs e)
    {
        info = CategoryDB.GetById(ConvertType.ToInt(_idCat));
        if (info.Parent == 0)
            Response.Redirect(_UrlCateL);
        else
            Response.Redirect(_UrlCateSub + info.Parent.ToString());
    }
}
